{# SPDX-FileCopyrightText: © 2014-2016 Siemens AG

   SPDX-License-Identifier: FSFAP
#}
{% extends "include/base.html.twig" %}

{% block content %}

{% if error is empty %}
<form name="Updatefm" action="{{ actionUri }}" method="post">
  <input type="hidden" name="req_marydone" value="{{ req_marydone }}"/>
  <input type="hidden" name="req_shortname" value="{{ req_shortname }}"/>
  <input type="hidden" name="rf_pk" value="{{ rf_pk }}"/>
  <input type="hidden" name="{% if rf_pk %}updateit{% else %}addit{% endif %}" value="true"/>
  <table>
    {% import 'include/macros.html.twig' as macro %}
    <tr>
      <td align="right"><label for="rf_active">{{ 'Active'|trans }}</label></td>
      <td align="left">{{ macro.select('rf_active',boolYesNoMap,'rf_active',rf_active) }}</td>
    </tr>
    <tr>
      <td align="right"><label for="marydone">{{ 'Checked'|trans }}</label></td>
      <td align="left">{{ macro.select('marydone',boolYesNoMap,'marydone',marydone) }}</td>
    </tr>
    <tr>
      <td align="right"><label for="rf_spdx_id">{{ 'SPDX ID'|trans }}{% if isReadOnly %} ({{ 'read only'|trans }}){% endif %}</label></td>
      <td><input type="text" name="rf_spdx_id" value="{{ rf_spdx_id|e }}" id="rf_spdx_id"
             size="30" {% if rfId and isReadOnly %} readonly="readonly"{% endif %}>
        ({{ 'used in report'|trans }})
      </td>
    </tr>
    <tr>
      <td align="right"><label for="rf_shortname">{{ "Short name"|trans }}</label></td>
      <td><input type="text" name="rf_shortname" value="{{ rf_shortname|e }}" id="rf_shortname"
                 size="30" {% if rfId %}readonly{% endif %}>
        ({{ 'must be unique'|trans }})
      </td>
    </tr>
    <tr>
      <td align="right"><label for="rf_fullname">{{ "Full name"|trans }}</label></td>
      <td><input type="text" name="rf_fullname" value="{{ rf_fullname|e }}"
                 id="rf_fullname" size="60"></td>
    </tr>
    <tr>
      <td align="right">
        <label for="rf_text">{{ 'License Text'|trans }}{% if isReadOnly %} ({{ 'read only'|trans }}){% endif %}</label>
      </td>
      <td><textarea name="rf_text" rows="10" cols="80" id="rf_text"
          {% if isReadOnly %}readonly="readonly"{% endif %}>{{ rf_text|e }}</textarea>
      </td>
    </tr>
    <tr>
      <td align="right"><label for="rf_text_updatable">{{ 'Text Updatable'|trans }}</label></td>
      <td align="left">{{ macro.select('rf_text_updatable',boolYesNoMap,'rf_text_updatable',rf_text_updatable) }}</td>
    </tr>
    <tr>
      <td align="right"><label for="rf_detector_type">{{ 'Detector Type'|trans }}</label></td>
      <td align="left">{{ macro.select('rf_detector_type',detectorTypes,'rf_detector_type',rf_detector_type) }}</td>
    </tr>
    <tr>
      <td align=right>
        <label for="rf_url">{{ 'URL'|trans }}</label>
        {% if rf_url %}<a href="{{ rf_url }}"><img border="0" src="images/right-point-bullet.gif"/></a>{% endif %}
      </td>
      <td><input type="text" name="rf_url" value="{{ rf_url }}" id="rf_url" size="60"></td>
    </tr>
    <tr>
      <td align="right"><label for="rf_notes">{{ 'Public notes'|trans }}</label></td>
      <td><textarea name="rf_notes" id="rf_notes" rows="5" cols="80">{{ rf_notes|e }}</textarea></td>
    </tr>
    <tr>
      <td align="right"><label for="rf_parent">{{ 'Conclusion'|trans }}</label></td>
      <td align="left">{{ macro.select('rf_parent',parentMap,'rf_parent',rf_parent, 'class="ui-render-select2"') }}</td>
    </tr>
    <tr>
      <td align="right"><label for="rf_report">{{ 'Reported license'|trans }}</label></td>
      <td align="left">{{ macro.select('rf_report',reportMap,'rf_report',rf_report, 'class="ui-render-select2"') }}</td>
    </tr>
    <tr>
      <td align="right"><label for="risk_level">{{ 'Risk level'|trans }}</label></td>
      <td align="left">{{ macro.selectsingle('risk_level',range(0,5),'risk_level',risk_level) }}</td>
    </tr>
    <tr>
      <td align="right"><label for="{{ obligationSelectorId }}">{{ "Associated Obligations"|trans }}</label></td>
      <td align="left">{{ macro.selectwitharray(obligationSelectorName, obligationTopics, obligationSelectorId, obligationSelected, 'style="min-width:575px;"', 8) }}</td>
    </tr>
  </table>
  {% if rfId %}
    <a href="?mod=admin_license_to_csv&amp;rf={{ rfId }}" class="buttonLink">{{ 'Export as CSV'|trans }}</a>
  {% endif %}
  <input type="submit" value="{% if rfId %}{{ 'Update'|trans }}{% else %}{{ 'Add license'|trans }}{% endif %}"/>
</form>
{% else %}
  {{ error }}
{% endif %}
{% endblock %}

{% block foot %}
  {{ parent() }}
  {% set riskSelectId = 'risk_level' %}
  <script type="text/javascript">{% include "riskLevel_select.js.twig" %}</script>
  <script type="text/javascript">
    $('#{{ obligationSelectorId }}').select2({'placeholder': 'Select obligations associated with this license'});
  </script>
{% endblock %}
